const { series,watch ,src,dest, task} = require('gulp');
var gulpClean = require('gulp-clean');

const ctr_path = '../story-client/src/contracts'

function clean(cb) {
  src(ctr_path, {read: false,allowEmpty:true})
  .pipe(gulpClean({force:true}));
  cb();
}

function copy(cb) {
  src('build/contracts/*.json')
  .pipe(dest('../story-client/src/contracts/'));
  cb()
}

task(clean)
task(copy)

const watcher = watch(['build/contracts/*.json']);
watcher.on('change', async function(path, stats) {
  console.log(`File ${path} was changed`);
  series(clean,copy)()
});

task('build', function(cb) {
  // body omitted
  cb();
});


exports.default = series(clean,copy);
exports.copy = copy;
exports.clean = clean;
